perf: overlap MTP final-draft-to-target graph updates.#1962
Draft
pjgao wants to merge 6 commits into
Draft
Conversation
pjgao
force-pushed
the
perf/npu-mtp-tp2-gapless
branch
from
July 19, 2026 14:40
65a1958 to
a74b00f
Compare
Collaborator
Author
|
PR #1962 已刷新到 本轮主要变化:
当前 head 已通过改动 production translation units 编译、TileLang kernel 生成及 NPU wrapper 单测 9/9。PR 描述已区分可归属于 #1962 的约 148.73 ms E2E 与 #1962+#1966 组合版本的约 145.9 ms,避免错误归因。 当前 PR 保持 Draft;切换 Ready 前会补充精确 head |
pjgao
force-pushed
the
perf/npu-mtp-tp2-gapless
branch
from
July 19, 2026 15:05
a74b00f to
26abdf0
Compare
- default unsupported models to the conservative runtime path - allow model implementations to declare verification requirements
- fuse token and persistent metadata writes for graph replay - update dynamic paged-attention tiling for verify widths 4, 5, and 6
- retain stable graph addresses for dynamic verification sources - apply fused token, metadata, and tiling updates during replay
- expose static graph-task preparation through the executor stack - preserve source identity and reuse captured replay tasks safely
Collaborator
Author
|
按评审主题重新拆分提交并更新远端,当前 head 为
拆分前 旧的已发布历史仍保存在本地 |
- prepare static target work while the final draft step executes - use model capabilities and fused graph updates for MTP3, MTP4, and MTP5 - retain conservative fallback behavior for unsupported layouts
- validate TileLang specializations for MTP3, MTP4, and MTP5 - cover graph task reuse and current batch block-manager APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目标与范围
本 PR 只优化 NPU MTP speculative decoding 中 final draft 完成到 target verification graph 启动 的边界。
main@abe92b83f26abdf093这样拆分后,本 PR 的性能归因和评审范围都只对应一个 pipeline 边界。
问题
优化前,最后一个 draft token 已经生成后,target graph 仍要串行等待 host 完成:
这些工作位于 final draft → target 的关键路径上,形成 host dispatch 空泡。
实现
1. 提前准备可静态确定的 target graph task
在 final draft 执行期间准备与最终 token 无关的 target graph task,并为动态输入保留稳定地址。final draft 完成后只保留真实的数据依赖,不再重新构建整套 target 输入。
2. 在 target graph 开头融合动态输入更新
新增三个 TileLang kernel family:
spec_verify_token_update:写入 base token 与各 draft token;spec_verify_metadata_update:更新 positions、KV lengths、slots、block table、linear state 等 persistent metadata;spec_verify_attention_tiling_update:更新 expanded paged-attention 的动态 tiling 字段。三类更新被 target graph 捕获,避免 replay 前额外的 graph-external D2D、同步 memcpy 或 ATB Setup。
3. 用模型能力契约替代模型名硬编码
新增
SpeculativeVerifyCapabilities:requires_causal_chunked_prefillsupports_in_graph_input_updateMTP runtime 只查询能力,不再判断
qwen3_5、mimo等模型字符串。能力在 target model 加载时缓存,decode 热路径不重复执行虚调用或字符串匹配。4. MTP3、MTP4、MTP5 使用同一条快路径
框架控制流不再写死
depth == 5或verify width == 6。TileLang 针对当前已验证的有限硬件形状生成:其他深度、multi-sequence、地址不稳定或布局不满足要求时自动回退到原路径。本 PR 不宣称支持任意 speculative depth 或 MTP8。
代码规模
相对
main@abe92b83f:+2587/-142+2123/-139+464/-3主要分布:
+1241/-129+359+378+112/-10+33+464/-3batch_test.cpp中另有+3/-3的 latest-main 测试 API 迁移,只用于保持该已有测试可编译,不影响 runtime。提交拆分
提交按依赖顺序组织,reviewer 可以逐层检查:
391a9855f+542c5ba940b+737b73cddbb8+396/-396edabdbf1+465/-7fd80f16b4+471/-9326abdf093+464/-3每个提交只承担一个评审主题。拆分前后的 Git tree 均为
d0de856c31eb106821900bca929ba2774e9fd900,因此本次历史整理没有改变任何最终源码内容。性能证据
main 与 #1962 语义版本
固定条件:Qwen3.5-2B、target TP2、draft body TP1、MTP5、NPU 14/15;ACL graph、schedule overlap、chunked prefill 开启;固定输入集,输出 25 tokens;warmup 8 后执行 20 requests × 3 rounds,共 60/60 成功请求。
accepted/draft 均为
1617/2610,输出内容及 token usage 一致。这里的约
148.73 ms是 #1962 单独能力的可归因结果。约145.9 ms的历史结果来自 #1962 与 #1966 组合版本,不作为本 PR 的单独收益声明。通用化重构开销
在固定 Qwen3.5-2B、TP2、MTP5 workload 上做过 A-B-A 重构前后测试:TPOT
-0.0278%、25-token E2E+0.0081%、吞吐-0.0084%,均小于 0.04% 且低于 2% 回退门槛。该测试来自通用化开发 lane,属于强支持证据;在 PR 从 Draft 切换为 Ready 前,仍会对当前精确 head
26abdf093补做 main/MTP3/MTP4/MTP5 同合同正式 A/B,不把旧 lineage 的绝对数冒充为当前 head 数据。当前 head 验证
git diff --check:通过;spec_verify_token_update_wrapper_test:4/4 通过;spec_verify_metadata_update_wrapper_test:3/3 通过;spec_verify_attention_tiling_update_wrapper_test:2/2 通过;回退边界
以下任一条件不满足时均使用原实现:
因此 Kimi、DeepSeek、DFlash 以及其他尚未适配的模型不会误入 Qwen3.5 的 fast path。